<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * Class CreateDormsTable.
 */
class CreateDormsTable extends Migration
{
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('dorms', function(Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('building_id')->nullable();
            $table->unsignedInteger('dorm_type_id')->nullable();
            $table->integer('floor');
            $table->string('code',20)->unique();//宿舍号
            $table->string('unit_name',16);//单元名
            $table->tinyInteger('beds')->default(4);
            $table->float('bed_rent')->default(20);//床位费
            $table->float('rent')->default(0);//租金
            $table->tinyInteger('for_gender')->nullable();
            $table->tinyInteger('status')->default(1);
            $table->integer('record_order')->default(0);
            $table->string('remark',120)->nullable(true);
            $table->timestamp('created_at')->useCurrent();
            $table->timestamp('updated_at')->useCurrent();
            $table->foreign('building_id')->references('id')->on('buildings')
                ->onDelete('cascade');
            $table->foreign('dorm_type_id')->references('id')->on('dorm_types')
                ->onDelete('set null');

		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('dorms');
	}
}
